<?php
require_once dirname(__FILE__)."/base_model.php";
class attachments extends base_model
{

	const ATTACHMENT_TABLE = "table_attachment";

	public function __construct()
	{
		parent::__construct();
	}

	/**
	 * 添加工作说明
	 * $row = array(
			'event_id'			=> $event_id,
			'attachment_owner'	=> $attachment_owner,
			'attachment_path'	=> $attachment_path,
			'attachment_name'	=> $attachment_name
		);
	 **/
	public function uploadAttachment(array $row)
	{
		return $this->db->insert(self::ATTACHMENT_TABLE, $row);;
	}

	/**
	 * 根据事件ID查询工作纪录
	 **/
	public function getAttachmentsById($eventId)
	{
		 $this->db->select("attachment_id, attachment_name, attachment_path, attachment_isreply");
		 $this->db->where("event_id", $eventId);
		 $this->db->from(self::ATTACHMENT_TABLE);
		 return $this->db->get()->result_array();
	}
	/**
	 *
	 * @param $where
	 *
	 * @return array
	 */
	public function getAttachments($where)
	{
//		 $this->db->select("attachment_id, attachment_name, attachment_path");
        foreach($where as $k=>$row) {
           if (is_array($row)) {
           	    $this->db->where_in($k, $row);
           	    unset($where[$k]);
           }
        }
		$this->db->where($where);
		$this->db->from(self::ATTACHMENT_TABLE);
	    return $this->db->get()->result_array();
	}
}